﻿namespace StudyCompanion.Commons.Cache;

/// <summary>
///     分布式锁
/// </summary>
public interface IDistributedLocker
{
    /// <summary>
    ///     加锁
    /// </summary>
    /// <param name="key"></param>
    /// <param name="expiry"></param>
    /// <returns></returns>
    (bool Success, string LockValue) Lock(string key, int expiry = 5000);

    /// <summary>
    ///     加锁
    /// </summary>
    /// <param name="key"></param>
    /// <param name="expiry"></param>
    /// <returns></returns>
    Task<(bool Success, string LockValue)> LockAsync(string key, int expiry = 5000);

    /// <summary>
    ///     解锁
    /// </summary>
    /// <param name="key"></param>
    /// <param name="lockValue"></param>
    /// <returns></returns>
    bool UnLock(string key, string lockValue);

    /// <summary>
    ///     解锁
    /// </summary>
    /// <param name="key"></param>
    /// <param name="lockValue"></param>
    /// <returns></returns>
    Task<bool> UnLockAsync(string key, string lockValue);
}